package com.why.amallrest.exceptionhandler;

import com.why.common.utils.HttpStatus;
import com.why.common.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author yasuo
 */
@Slf4j
@ControllerAdvice("com.why.controller")
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody //为了能够返回数据
    public Result error(Exception e) {
        log.error("捕获到异常:", e);
        return Result.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), "服务器内部错误！");

    }

}